<script>
export default {
	onLaunch: function() {
		plus.runtime.setBadgeNumber(0);
	},
	onHide: function() {
    },
	onShow() {
		this.$store.commit({
			type: 'setAiSearch',
			aiSearch: true
		});
		// 监听通知栏消息点击
		plus.push.addEventListener('click', (res) => {
			if (plus.os.name === 'Android') {
				let params = {
					title: res.title,
					cid: plus.push.getClientInfo().clientid
				}
				this.$service.common.userHf.gt(params).then(res => {
					console.log(res)
					
					setTimeout(() => {
						if (uni.getStorageSync('token')) {
							if (res.jumpUrl) {
								uni.navigateTo({
								    url: res.jumpUrl
								});
							} else if (res.type === 1) {
								uni.navigateTo({
								    url: '/pages/news/detail?id=' + res.id
								});
							}
						}
					}, 2000)
				});
			} else {
				this.$service.common.userHf.gt({
					title: res.aps.alert.title,
					cid: plus.push.getClientInfo().clientid
				}).then(res => {
					console.log(res)
					
					setTimeout(() => {
						if (uni.getStorageSync('token')) {
							if (res.jumpUrl) {
								uni.navigateTo({
								    url: res.jumpUrl
								});
							} else if (res.type === 1) {
								uni.navigateTo({
								    url: '/pages/news/detail?id=' + res.id
								});
							}
						}
					}, 2000)
				});
			}
		});

		// 获取功能权限
		// #ifdef H5
		this.$store.dispatch('getPermInfo', { version: '1.1.0', os: 1 });
		// #endif
		// #ifdef APP-PLUS
		plus.runtime.getProperty(plus.runtime.appid, wgtinfo => {
			let params = { ...wgtinfo };
			let os = plus.os.name;
			if (os === 'Android') {
				params.os = 1;
			} else {
				params.os = 0;
			}
			this.$store.dispatch('getPermInfo', params);
		});
		// #endif
	}
};
</script>

<style lang="scss">
@import './static/scss/index.scss';
page {
	background: #f5f7fb;
}
</style>
